#include <zenilib.h>
#include "Weapon.h"

using namespace std;

Weapon::Weapon(WeaponType type_, Player* wielder_) :
	GameObject(),
	type(type_),
	wielder(wielder_),
	timeSinceFire(0),
	canFire(true)
{
	switch (type){
		case UZI:
			setScale(Vector2(25, 25));
			addTexture("Uzi");
			fireDelay = 0.1f;
			break;
		case LASER:
			setScale(Vector2(25, 25));
			addTexture("LaserGun");
			fireDelay = 0.25f;
			break;
		case SHURIKEN:
			setScale(Vector2(25, 25));
			addTexture("Shuriken");
			fireDelay = 0.35f;
			break;
		case BIGGUN:
			setScale(Vector2(80, 40));
			addTexture("BigGun");
			fireDelay = 0.5f;
			break;
	}
}

void Weapon::update(const float & timestep)
{
	if (!canFire){
		timeSinceFire += timestep;
		if (timeSinceFire > fireDelay){
			canFire = true;
			timeSinceFire = 0;
		}
	}
}

vector<Projectile*> Weapon::fireProjectile()
{
	vector<Projectile*> projectiles;
	if (canFire){
		canFire = false;
		switch (type){
			case UZI:
				projectiles.push_back(new Projectile(pos + Vector2(0, -9), flipped, type, wielder));
				break;
			case LASER:
				projectiles.push_back(new Projectile(pos + Vector2(flipped ? -5 : 5, 0), flipped, type, wielder));
				break;
			case SHURIKEN:
				projectiles.push_back(new Projectile(pos, flipped, type, wielder));
				projectiles.push_back(new Projectile(pos, flipped, type, wielder));
				projectiles.push_back(new Projectile(pos, flipped, type, wielder));
				projectiles[1]->setVel(projectiles[1]->getVel().rotate(pi / 8));
				projectiles[2]->setVel(projectiles[2]->getVel().rotate(-pi / 8));
				break;
			case BIGGUN:
				projectiles.push_back(new Projectile(pos + Vector2(flipped ? -10 : 10, -1), flipped, type, wielder));
				break;
		}
	}
	return projectiles;
}